package cn.tedu.store.interceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.web.servlet.HandlerInterceptor;

public class LoginInterceptor implements HandlerInterceptor {

	@Override
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
			throws Exception {
		//获取Session对象
		HttpSession session = request.getSession();
		//判断Session中有没有uid，因为我们登录的时候session.setAttribute("uid", data.getUid());
		if(session.getAttribute("uid")==null) {
			//没有uid，即表示未登录，或登录超时了，则重定向到登录页面
			response.sendRedirect("/web/login.html");
			//执行拦截
			return false;
		}
		
		//放行
		return true;
	}

}
